package com.los;

import java.util.concurrent.ForkJoinPool;

/**
 * @program: java8
 * @description: 并行
 * @author: Yujuan
 * @create: 2018-07-01 15:46
 **/
public class ForkJoinPoolTest {
    private static int[] data={1,2,3,4,5,6,7,8,9,10};

    public static void main(String[] args) {
        System.out.println("result="+calc());
        AccumulatorRecursiveTask task=new AccumulatorRecursiveTask(0,data.length,data);
        ForkJoinPool forkJoinPool=new ForkJoinPool();
        Integer result=forkJoinPool.invoke(task);
        System.out.println("AccumulatorRecursiveTask>>"+result);
    }

    private static int calc(){
        int result=0;
        for (int i=0;i<data.length;i++){
            result+=data[i];
        }
        return result;
    }
}
